package com.example.forum.interceptor;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

@Configuration
public class AppInterceptorConfigurer implements WebMvcConfigurer {
    @Resource // 注入自定义拦截器
    private LoginInterceptor loginInterceptor ;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 添加拦截规则
        registry.addInterceptor(loginInterceptor)
                .addPathPatterns("/**")  // 拦截所有接口
                .excludePathPatterns("/sign-in.html")
                .excludePathPatterns("/sign-up.html")
                .excludePathPatterns("/user/login")
                .excludePathPatterns("/user/register")
                .excludePathPatterns("/user/logout")
                .excludePathPatterns("/swagger*/**")
                .excludePathPatterns("/v3*/**")
                .excludePathPatterns("/dist/**") // 排除所有静态⽂件
                .excludePathPatterns("/image/**")
                .excludePathPatterns("/**.ico")
                .excludePathPatterns("/js/**");

    }
}
